<?php

// +----------------------------------------------------------------------
// | H1CMS © OpenSource CMS
// +----------------------------------------------------------------------
// | Copyright (c) 2014-2016 http://www.h1cms.com All rights reserved.
// | Copyright (c) 2014-2016 嘉兴领格信息技术有限公司，并保留所有权利。
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Allen <allen@lg4.cn>
// +----------------------------------------------------------------------

namespace Lg\Session;

use Symfony\Component\HttpFoundation\Session\Session as SymfonySession;

/**
 * Description of Session
 *
 * @author Allen <allen@lg4.cn>
 */
class Session extends SymfonySession {

    use \Lg\Traits\SingletonTrait;
    /**
     * @var $instance \Symfony\Component\HttpFoundation\Session\Session
     */
    
    const INOUT_FORWARD = '_forward.input';
    /**
     * 
     * @param string $type (notice|error|success|warning|info)
     * @param string $message
     */
    public function addFlash($type, $message) {
        $this->getFlashBag()->add($type, $message);
    }

    /**
     * 
     * @param string $type
     * @param array $default
     * @return string
     */
    public function getFlash($type, array $default = array()) {
        return $this->getFlashBag()->get($type, $default);
    }

    /**
     * 
     * @param string $type
     * @return array
     */
    public function hasFlash($type) {
        return $this->getFlashBag()->has($type);
    }

    /**
     * 
     * @return array
     */
    public function allFlash() {
        return $this->getFlashBag()->all();
    }

    /**
     * 
     * @return \Symfony\Component\HttpFoundation\Session\Flash\FlashBag
     */
    public function flash() {
        return $this->getFlashBag();
    }

    public function increment($key, $amount = 1) {
        $value = $this->get($key, 0) + $amount;
        $this->set($key, $value);
        return $value;
    }

    public function decrement($key, $amount = 1) {
        return $this->increment($key, $amount * -1);
    }
    
}
